import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/viewmodel/medecine/medicine_handover/add_medicine_hand_over_view_model.dart';
import 'package:ls_work/widgets/common_widget.dart';
class AddMedicineHandoverPage extends BaseStatefulMvvmWidget{

  @override
  State<StatefulWidget> createState() => _AddMedicineHandoverState();

}

class _AddMedicineHandoverState extends BaseMvvmState<AddMedicineHandOverViewModel,AddMedicineHandoverPage>{
  @override
  Widget? buildLoadingContentView() {
    return SingleChildScrollView(
      padding: EdgeInsets.symmetric(horizontal: 16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ...[
            TitleValueWidget(title: '长者姓名', value: viewModel.elderInfo?.customerName??"",arrow: Icon(Icons.keyboard_arrow_right_outlined)).onTap(() {
              viewModel.chooseElder();
            },highlightColor: Colors.transparent,splashColor: Colors.transparent),
            TitleValueWidget(title: '床位号', value: viewModel.elderInfo?.bedNo??"",hint: '根据长者自动显示'),
            TitleValueWidget(title: '性别', value: viewModel.elderInfo?.sexName??"",hint: '根据长者自动显示'),
            TitleValueWidget(title: '药品名称', value: viewModel.drugInfo?.commonName??"",arrow: Icon(Icons.keyboard_arrow_right_outlined)).onTap(() {
              viewModel.chooseMedicine();
            },highlightColor: Colors.transparent,splashColor: Colors.transparent),
            TitleValueWidget(title: '药品规格', value:viewModel.drugInfo?.specifications??"",hint: '根据选择的药品自动显示'),
            TitleValueWidget(title: '包装单位', value:viewModel.drugInfo?.maxUnitName??"",hint: '根据选择的药品自动显示'),
            TitleValueWidget(title: '最小单位', value:viewModel.drugInfo?.minUnitName??"",hint: '根据选择的药品自动显示'),
            Column(
              children: [
                TitleValueWidget(title: '移交原因', value: '',hint: ''),
                NoBorderInput(hintText: '请输入原因',onChanged: (str){
                  viewModel.reason = str;
                },minLines: 4,maxLines: 4,).addToContainer(
                  decoration: BoxDecoration(color:Colours.bg_color,borderRadius: 5.borderRadius),
                  padding: EdgeInsets.symmetric(horizontal: 10,vertical: 10),
                )
              ],
            ),
            TitleContentWidget(
                title: '移交数量(包装)',
                child: NoBorderInput(
                    hintText: '仅输入正整数',
                    onChanged: (str) {
                      viewModel.packageNum = str;
                      viewModel.calculateReceiveNum();
                    },
                    maxLines: 1,
                    keyboardType: CommonInputType.number)),
            TitleContentWidget(
                title: '移交数量(最小单位)',
                child: NoBorderInput(
                    hintText: '仅输入正整数',
                    onChanged: (str) {
                      viewModel.unitNum = str;
                      viewModel.calculateReceiveNum();
                    },
                    maxLines: 1,
                    keyboardType: CommonInputType.number)),
            TitleValueWidget(
                title: '合计移交数量', value: viewModel.totalNum, hint: '自动计算'),


            CheckWithText(title: '用药计划是否改为已移交', onChanged: (value){
              setState(() {
                viewModel.isTransfer = value?1:0;
              });
            },defaultSelected: viewModel.isTransfer==1,).addToContainer(
              margin: EdgeInsets.symmetric(vertical: 10)
            ),

            

          ].insertWidget(Gaps.dividerLine)
        ],
      ),
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('新增药品移交'),
      ),
      body: Column(
        children: [
          loadingContentWidget.setWeight(1),

          SizedBox(height: 10,),
          TextButton(onPressed: (){
            viewModel.submitClick();
          }, child: CommonText('确认移交',textColor: Colors.white),
          style: ButtonStyle(
            backgroundColor: WidgetStateProperty.all(Colors.blue),
            shape: WidgetStateProperty.all(StadiumBorder()),
            minimumSize: WidgetStateProperty.all(Size(MediaQuery.of(context).size.width-32,45))
          ),),
          SizedBox(height: 12,),
        ],
      ),
    );
  }

  @override
  AddMedicineHandOverViewModel createViewModel() {
    return AddMedicineHandOverViewModel(context);
  }

  @override
  void onRetryClick() {
  }

}